#ifndef CONTROLLER_H
#define CONTROLLER_H

#include <QGraphicsItem>
#include <QObject>
#include "CGenAlg.h"
#include "mines.h"
#include "Minesweeper.h"
#include "fstream"

class Controller : public QWidget
{
    Q_OBJECT

signals:
    void keyCaught(QKeyEvent *e);

public:
    Controller(QGraphicsScene *scene);
    virtual ~Controller();
    Minesweeper **mineSweepers;

    void setMineArray(mines *m[]);
    void init();
    void checkCollision();
    int getGeneration();

    mines **getMineArray();
    Minesweeper **getMineSweeperArray();
    static vector<SVector2D> v_mines;

protected:
    void timerEvent(QTimerEvent *event);
    virtual void keyPressEvent(QKeyEvent *);
    void  mousePressEvent ( QMouseEvent * event );

private:
    QString gen, genNum, sTicks, sTicksNum, sFitness, fitnessNum, sAvgFitness, avgFitnessNum;
    QGraphicsTextItem *genText, *ticksText, *fitnessText, *avgFitnessText;
    QGraphicsScene *scene;
    char* fileName;
    int ticks;
    int generation;
    int numWeightsInNN;

    mines **a_mines;
    Minesweeper *m;
    CGenAlg *gAlgo;
    SGenome bestSweeper;
    vector<SGenome> vecThePopulation;
    double getHighestFitness();
    double getAvgFitness();
    ofstream output;
};

#endif // CONTROLLER_H
